package com.ruoyi.system.controller.web;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.enums.WebIndexEnum;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.api.domain.SysLogininfor;
import com.ruoyi.system.api.model.LoginUser;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 查询左侧栏目
 */
@ApiOperation("联赛")
@RestController
@RequestMapping("/web/index")
public class BaseWebController extends BaseController
{
    @Resource
    private TokenService tokenService;
    /**
     * 查询左侧栏目
     */
    @GetMapping("/list")
    @Operation(summary = "查询左侧栏目", description = "查询左侧栏目")
    public AjaxResult list()
    {
        LoginUser loginUser = tokenService.getLoginUser();
        if (Objects.isNull(loginUser)){
            return error("请先登录");
        }
        List<Map<String, Object>> list = new ArrayList<>();
        for (WebIndexEnum value: WebIndexEnum.values()) {
            Map<String, Object> map = new HashMap<>();
            Map<String,String> meta = new HashMap<>();
            meta.put("title",value.getMeta());


            map.put("path",value.getPath());
            map.put("name",value.getName());
            map.put("meta",meta);
            map.put("component",value.getComponent());
            list.add(map);
        }
        if (Objects.equals(loginUser.getUserid(),171481617989977966L)){
            return success(list);
        }
        list = list.stream().filter(bo -> !Objects.equals(bo.get("path"), "/table_basic")).collect(Collectors.toList());
        return success(list);
    }
}
